<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>三元运算符示例</title>
</head>
<body>
    <label for="theme">Select Theme：</label>
    <select name="" id="theme">      
        <option value="white">White</option>
        <option value="black">Black</option>
    </select>
    <h1>更改背景</h1>

    <script>
        var html = document.querySelector('html');
        var select = document.querySelector("select");

        select.onchange = function(){
            (select.value == 'black') ? changeColor('black', 'white') : changeColor('white', 'black');
        }

        function changeColor(bgColor, textColor){
            html.style.backgroundColor = bgColor;
            html.style.color = textColor;
        }
        
    </script>
</body>
</html>